const { defineConfig } = require("@vue/cli-service");
const { name } = require("./package.json");
const px2rem = require("postcss-pxtorem");
const postcss = px2rem({
  rootValue: 100,
  propList: ["*"],
  // exclude: /(node_modules)/,
  selectorBlackList: [".logo-container"],
});
module.exports = defineConfig({
  transpileDependencies: true,
  css: {
    loaderOptions: {
      postcss: {
        postcssOptions: {
          plugins: [postcss],
        },
      },
      // 给 sass-loader 传递选项
      sass: {
        // @/ 是 src/ 的别名
        additionalData: `@import "@/styles/mixins.scss";
              @import "@/styles/variables.scss";`,
      },
    },
  }, // 打包时去除console
  terser: {
    terserOptions: {
      compress: {
        drop_console: true,
        drop_debugger: true,
      },
    },
  },
  devServer: {
    port: 5312,
    proxy: {
      "/algo/": {
        target: "http://122.9.78.91:30000",
        ws: true,
        pathRewrite: {
          "^/algo/": "/algo/",
        },
      },
      "^/order/": {
        target: "http://122.9.78.91:30000",
        ws: true,
        pathRewrite: {
          "^/order/": "/order/",
        },
      },
      "/eco": {
        target: "http://122.9.78.91:30000",
        ws: true,
        pathRewrite: {
          "^/eco": "/eco",
        },
      },
      "/ams": {
        target: "http://122.9.78.91:30000",
        ws: true,
        pathRewrite: {
          "^/ams": "/ams",
        },
      },
      "/aiShopAssets": {
        target: "http://dev.aicenter.defaulttenant.lcap.visb.cloud:50080",
        ws: true,
        pathRewrite: {
          "^/aiShopAssets": "",
        },
      },
    },
  },
  chainWebpack: (config) => {
    config.plugin("html").tap((args) => {
      args[0].title = "组件商城";
      return args;
    });
  },
  configureWebpack: {
    devtool:
      process.env.NODE_ENV === "production"
        ? "hidden-source-map"
        : "source-map",
    output: {
      library: `${name}-[name]`,
      libraryTarget: "umd",
      chunkLoadingGlobal: `webpackJsonp_${name}`,
    },
  },
});
